package cn.lg.soar.general.feign.fallback;

import cn.lg.soar.core.util.InnerSerializeUtils;
import cn.lg.soar.general.api.model.RegionDTO;
import cn.lg.soar.general.feign.RegionApiFeign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * 区域接口
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public class RegionApiFallbackFactory implements FallbackFactory<RegionApiFeign> {

    protected static final Logger LOGGER = LoggerFactory.getLogger(RegionApiFallbackFactory.class);

    @Override
    public RegionApiFeign create(Throwable cause) {
        return new RegionApiFeign() {

            @Override
            public RegionDTO getById(int id) {
                LOGGER.error("getById：{}", id, cause);
                return null;
            }

            @Override
            public List<RegionDTO> listByIds(Collection<Integer> ids) {
                LOGGER.error("listByIds：{}", InnerSerializeUtils.toJson(ids), cause);
                return Collections.emptyList();
            }

            @Override
            public List<RegionDTO> getRegionPath(int id) {
                LOGGER.error("getRegionPath：{}", id, cause);
                return Collections.emptyList();
            }

            @Override
            public List<String> getNameList(int id) {
                LOGGER.error("getNameList：{}", id, cause);
                return Collections.emptyList();
            }

            @Override
            public Map<Integer, List<String>> getNameListMap(Collection<Integer> ids) {
                LOGGER.error("getNameListMap：{}", InnerSerializeUtils.toJson(ids), cause);
                return Collections.emptyMap();
            }
        };
    }
}
